//
//  SignatureModel.m
//  Bees
//
//  Created by NowYouCanSee on 2019/2/19.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "SignatureModel.h"

@implementation TransactionModel

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"actions" : [SignatureModel class],
             };
}
@end

@implementation SignatureModel

- (NSDictionary*)jsonData{
    if ([_jsonData.allKeys containsObject:@"options"]) {
        NSMutableDictionary*mutableData = _jsonData.mutableCopy;
        [mutableData removeObjectForKey:@"options"];
        return mutableData.copy;
    }else{
        return _jsonData;
    }
}

- (NSString*)jsonStr{
    NSArray*jsonArr = @[@{@"account":VALIDATE_STRING(self.account),@"name":VALIDATE_STRING(self.name),@"data":self.jsonData?:@{},@"authorization":self.authorization?:@[]}];
    NSData *data=[NSJSONSerialization dataWithJSONObject:jsonArr options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    DLog(@"jsonStr  = \n  %@",jsonStr);
    return jsonStr;
}

- (NSString*)permissions{
    NSDictionary *authorizationDic = [self.authorization objectOrNilAtIndex:0];
    if (authorizationDic && ValidDict(authorizationDic)) {
        return [NSString stringWithFormat:@"%@@%@",authorizationDic[@"actor"],authorizationDic[@"permission"]];
//        return [NSString stringWithFormat:@"%@@%@",authorizationDic[@"actor"],@"22222"];
    }
    return @"";
}
@end
